<template>
  <el-dialog
    :before-close="beforeClose"
    :visible.sync="show"
    :title="title"
    width="35%"
    append-to-body
    @close="close"
    @closed="closed"
  >
    <el-form label-width="100px" :model="form">
      <el-row>
        <el-col :span="12">
          <el-form-item label="姓名">
            <el-input
              v-model="form.item"
              type="text"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="手机号">
            <el-input
              v-model="form.item"
              type="text"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12"> <el-form-item label="身份证">
          <el-input
            v-model="form.item"
            type="text"
          />
        </el-form-item></el-col>
        <el-col :span="12"> <el-form-item label="所属楼宇">
          <el-input
            v-model="form.item"
            type="text"
          />
        </el-form-item></el-col>
      </el-row>
      <el-row>
        <el-col :span="12"> <el-form-item label="所属单位">
          <el-input
            v-model="form.item"
            type="text"
          />
        </el-form-item></el-col>

      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="户籍地址">
            <el-input
              v-model="form.item"
              type="text"
            />
          </el-form-item></el-col>

      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="现住地址">
            <el-input
              v-model="form.item"
              type="text"
            />
          </el-form-item></el-col>

      </el-row>

    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="handleClose">取 消</el-button>
      <el-button type="primary" @click="handleSubmit">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { ssqOptions, streetOptions, adminOptions } from '@/list/data'
export default {
  name: 'Index',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    type: {
      type: String,
      default: 'view'
    },
    data: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      show: false,
      ssqOptions,
      streetOptions,
      adminOptions,
      form: {
        ssq: '',
        street: '',
        admin: '',
        remark: ''
      }
    }
  },
  computed: {
    title() {
      let text = ''
      switch (this.type) {
        case 'view':
          text = '查看'
          break
        case 'create':
          text = '新建'
          break
        case 'edit':
          text = '编辑'
          break
      }
      return text
    }
  },
  watch: {
    visible(val) {
      if (val) {
        this.show = val
      }
    }
  },
  mounted() {
    this.show = this.visible
  },
  methods: {
    handleChange(value) {
      console.log(value)
    },
    getData() {
      console.log('获取数据')
    },
    handleClose() {
      console.log('点击关闭')
      this.beforeClose()
    },
    handleSubmit() {
      console.log('点击确定')
      this.$notify.success('保存成功')
      this.handleClose()
    },
    beforeClose() {
      console.log('关闭前的回调')
      this.show = false
      this.$emit('update:visible', false)
    },
    close() {
      console.log('关闭的回调')
    },
    closed() {
      console.log('关闭动画结束后的回调')
    }
  }
}
</script>

<style scoped>
</style>
